<?php
getDB();
class ausersData extends DBData
{
    public $tablename;
    public function __construct()
    {
        $this->tablename = 'ausers';
    }
    public function denglu($uname,$pwd)
    {
        $tab = $this->tablename;
        $where['user_name'] = $uname;
        $where['user_pass'] = $pwd;
        $arr = $this->Record("id,real_name,quanxianid", $where, $tab);
        if($arr)
        {
            $id = $arr['id']; 
            $_SESSION['admin_uid'] = $id;
        }
        return $arr;
    }
    public function getquanxian($id)
    {
        $sql = "select t2.quanxian,t2.mark from ausers t inner join lzh_quanxian t2 on t.quanxianid=t2.id where t.id='$id'";
        $arr = DBData::select($sql);
        $quanxian = $arr['quanxian'];
        $mark = $arr['mark'];
        $sql = "select id,fid,title as name,leixing,url from lzh_quanxian_mx where id in ($quanxian) order by px asc";
        $arrList = DBData::selectlist($sql);
        $list = $this->handle($arrList);

        $markArr = explode(",",$mark);
        $markArr = array_flip($markArr);
        return array(
            'list'=>$list,
            'markArr'=>$markArr
        );
    }
    
    public function handle($arrList)
    {
        $List_0 = array();
        $List_1 = array();
        $List_2 = array();
        foreach($arrList as $arr)
        {
            $leixing = $arr['leixing'];
            $id = $arr['id'];
            $arr['icon'] = 'el-icon-document-remove';
            switch ($leixing)
            {
                case 0:
                    $List_0[$id] = $arr;
                    break;
                case 1:
                    $List_1[$id] = $arr;
                    break;
                case 2:
                    $List_2[$id] = $arr;
                    break;
            }
        }
        foreach($List_2 as $arr)
        {
            $fid = $arr['fid'];
            if(isset($List_0[$fid]))
            {
                $List_0[$fid]['childList'][] = $arr;
            }
            if(isset($List_1[$fid]))
            {
                $List_1[$fid]['childList'][] = $arr;
            }
        }
        foreach($List_1 as $arr)
        {
            $fid = $arr['fid'];
            if(isset($List_0[$fid]))
            {
                $List_0[$fid]['childList'][] = $arr;
            }
        }
        $newArr = array();
        foreach($List_0 as $arr)
        {
            $newArr[] = array(
                'id'=>$arr['id'],
                'name'=>$arr['name'],
                'icon'=>$arr['icon'],
                'childList'=>$arr['childList']
            );
        }
        return $newArr;
    }
    
}
?>